lexer grammar Analexml;

options {
  language = Java;
}

@header {
package PL.prac4;
}
 @rulecatch { catch (RecognitionException e) {
   throw e;}
  }
  
  @lexer::members {
public class MiToken extends CommonToken {
  private String nuevoAtributo;
  
  public MiToken (CharStream input, int type, int channel, int start, int stop) {
    super(input, type, channel, start, stop);
    nuevoAtributo = getSourceName();
  }
  public void setNuevoAtributo(String s) {
  nuevoAtributo=s;
  }
  public String getNuevoAtributo() {
  return nuevoAtributo;
  }
  public String toString() {
  String aux;
  aux = "Linea " + getLine() + ", "+ getCharPositionInLine()+ ": encontrado "+ getText() + ", Regla: " + getType();
  return aux;
  }
}
// override standard token emission
public Token emit() {
    MiToken t = new MiToken(input, state.type, state.channel,
                    state.tokenStartCharIndex, getCharIndex()-1);
    t.setLine(state.tokenStartLine);
    t.setText(state.text);
    t.setCharPositionInLine(state.tokenStartCharPositionInLine);
    emit(t);
    return t;
}

}
  fragment NUEVA_LINEA: '\r\n';
  BLANCO: (' '|'\t'|NUEVA_LINEA) {$channel = HIDDEN;};
  
  fragment DIGITO: '0'..'9';
  fragment LETRA: ('a'..'z')|('A'..'Z');
  fragment IDENT: (LETRA|'_') (DIGITO|LETRA|'_')*;
  
  START_TAG: '<' IDENT '>';
  END_TAG: '</' IDENT '>';
  
  TEXT: (~('<'|'&')|'&amp;'|'&gt;')+;
  
  COMENTARIO: ('<!--' (options {greedy=false;}:.)* '-->') {$channel = HIDDEN;};
  